package com.lottery.football.controller;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.htmlparser.tags.TableTag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lottery.football.util.Constants;
import com.lottery.football.util.ContentParser;
import com.lottery.football.util.Spiders;

@Controller
@RequestMapping("/prediction")
public class PredictionController
{
	@RequestMapping(value = "/ajax/getPage.do", method = RequestMethod.POST)
	@ResponseBody  
	public Object getHistoryPage()
	{
		// Map<String, String> map =new HashMap<String, String>();
		// map.put("success", "true");
		
		String url = "http://space.500.com/ajax/ajaxhistory.php?m=history&a=historyquan&uid=493836&lotid=1&playid=1&u=长远利益&seltype=0&pageno=1";
		String jsonData = Spiders.get(url, Constants.GB2312);
		int startIndex = jsonData.indexOf("<div");
		int endIndex = jsonData.lastIndexOf("\"");
		String html = jsonData.substring(startIndex, endIndex);
		TableTag table = ContentParser.parseTag(html, TableTag.class, "class", "user_fa");
		System.out.println("-----json : " + jsonData);
		return jsonData;
	}
	
	@RequestMapping("/historyPage.do")
	public ModelAndView historyPage()
	{
		return new ModelAndView("/prediction/prediction");
	}
}
